package b3.widget.home.town
{
	import b3.config.*;
	import b3.model.*;
	import b3.net.*;
	import b3.util.*;
	import b3.scene.home.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;

	public class StateItem extends Sprite
	{
		private var stateInfo:StateInfo;
		
		public function StateItem(stateInfo:StateInfo)
		{
			super();
			this.stateInfo = stateInfo;
			var stateconfig:StateConfig = Config.stateConfigs[stateInfo.state];
			var StateIcon:Class = ResourceHelper.getInstance().getClassByName(stateconfig.iconImage[0]);
			var stateIcon:Sprite = new StateIcon();
			stateIcon.height = 20;
			stateIcon.scaleX = stateIcon.scaleY;
			stateIcon.x = 65;
			addChild(stateIcon);
			this.mouseChildren = false;
			this.addEventListener(MouseEvent.MOUSE_OVER,onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
		
		//获得街区信息
		private function getStateInfo():Sprite
		{
			var container:Sprite = new Sprite();
			var stateconfig:StateConfig = Config.stateConfigs[stateInfo.state];		
			//图标
			var IconImage:Class = ResourceHelper.getInstance().getClassByName(stateconfig.iconImage[0]);
			var iconImage:Sprite = new IconImage();
			iconImage.height = 50;
			iconImage.scaleX = iconImage.scaleY;
			container.addChild(iconImage);
			//作用描述
			var descriptionText:TextField = new TextField();
			descriptionText.selectable = false;
			descriptionText.autoSize = TextFieldAutoSize.LEFT;
			descriptionText.defaultTextFormat = new TextFormat("微软雅黑", 20, 0xFFFFFF, true);
			descriptionText.filters = [new GlowFilter(0xFFAA00, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			descriptionText.text = stateconfig.description;
			descriptionText.x = 65;
			descriptionText.y = 0;
			container.addChild(descriptionText);
			//剩余次数
			if (stateInfo.leftTimes > 0)
			{
				var leftTimesText:TextField = new TextField();
				leftTimesText.selectable = false;
				leftTimesText.autoSize = TextFieldAutoSize.LEFT;
				leftTimesText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x000000, true);
				leftTimesText.htmlText = "（剩余次数: <i>" + stateInfo.leftTimes + "</i>）";
				leftTimesText.x = descriptionText.x + Math.max((descriptionText.width - leftTimesText.width) / 2, 0);
				leftTimesText.y = 30;
				container.addChild(leftTimesText);
			}
			return container;
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			HomeScene.getInstance().centerInfoPane.showInfo(getStateInfo());
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			HomeScene.getInstance().centerInfoPane.clear();
		}
	}
}